from datetime import timedelta
import sys
import os

import pygame


def seconds_to_hms(seconds):
    return str(timedelta(seconds=seconds))


def scaled_img_by_width(original_img: pygame.Surface, new_width):
    """等比例缩放图片"""
    # 获取原始图像的宽度和高度
    original_width = original_img.get_width()
    original_height = original_img.get_height()
    # 指定新的宽度
    # new_width = board.board_width * 0.5
    # 计算新的高度，保持宽高比
    new_height = (new_width / original_width) * original_height
    # 调整图像大小
    scaled_win_img = pygame.transform.scale(
        original_img, (new_width, new_height))
    return scaled_win_img


def get_resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)
